var mysqlUtil = require('../util/mysqlUtil');
var EventProxy = require('eventproxy');

/**
 * 初始化
 * 初始化工作组
 */
var init = function(req, res) {
    // 获取用户信息
    var user = req.session.user;
    var obj = {
        curUserName: req.session.user.name,
        isTester: req.session.user.is_tester
    };
    res.render('home/index', obj);
};

var changeWorkGroup = function(req, res) {
    var workGroupId = req.query.id;

    // 检查当前用户是否有访问选择的工作组的权限
    var hasPermission = false;
    var workGroups = req.session.workGroups;
    for (var i = 0; i < workGroups.length; i++) {
        if (workGroups[i].id == workGroupId) {
            hasPermission = true;
            break;
        }
    }

    if (hasPermission)
        req.session.curWorkGroupId = workGroupId;

    init(req, res);
};

exports.init = init;
exports.changeWorkGroup = changeWorkGroup;